package com.lenovo.smarttraffic.ui.fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.lenovo.smarttraffic.R;

import static com.lenovo.smarttraffic.ui.fragment.FirstFragment.list_history;

public class SecondFragment extends BaseFragment {
    private TextView tvAllMoney;
    private ListView lvHistory;
    private Adapter_History adapter_history;
    private int AllMoney = 0;


    @Override
    public void onSupportVisible() {
        super.onSupportVisible();
        adapter_history.notifyDataSetChanged();
        for (int i = 0; i < list_history.size(); i++) {
            AllMoney += list_history.get(i).getMoney();
        }
        tvAllMoney.setText("充值总金额："+AllMoney+"元");
    }

    @Override
    protected View getSuccessView() {
        View view = LayoutInflater.from(mContext).inflate(R.layout._zjh_fg2_history, null, false);
        initView(view);

        return view;
    }

    private void initView(View view) {
        tvAllMoney = (TextView) view.findViewById(R.id.tv_AllMoney);
        lvHistory = (ListView) view.findViewById(R.id.lv_history);

        adapter_history = new Adapter_History();
        lvHistory.setAdapter(adapter_history);



    }

    private class Adapter_History extends BaseAdapter {
        private TextView tvAddMon;
        private TextView tvID;
        private TextView tvAddTime;


        @Override
        public int getCount() {
            return list_history.size();
        }

        @Override
        public Object getItem(int position) {
            return list_history.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout._zjh_layout_historyitem, parent, false);
            tvAddMon = (TextView) convertView.findViewById(R.id.tv_AddMon);
            tvID = (TextView) convertView.findViewById(R.id.tv_ID);
            tvAddTime = (TextView) convertView.findViewById(R.id.tv_AddTime);

            tvID.setText(list_history.get(position).getId() + "");
            tvAddMon.setText(list_history.get(position).getMoney() + "");
            tvAddTime.setText(list_history.get(position).getTime());

            return convertView;
        }
    }

    @Override
    protected Object requestData() {
        return "";
    }

    @Override
    public void onClick(View view) {

    }
}
